package main

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql" // import mysql driver
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"net"
)

type User struct {
	gorm.Model
	Age int
	Name string
}

func main() {
	var db *gorm.DB
	var err error
	connectstr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=%s&loc=Local&readTimeout=%s&writeTimeout=%s&parseTime=true", "baas", "baas", net.JoinHostPort("192.168.9.116", "38255"), "test", "utf8", "10s", "20s")
	if db, err = gorm.Open(mysql.Open(connectstr), &gorm.Config{}); err != nil {
		panic(err.Error())
	} else {
		sqlDB, _ := db.DB()
		sqlDB.SetMaxOpenConns(20)
	}
	db.AutoMigrate(&User{})
	user := User{
		Name: "aaa",
		Age: 11,
	}
	db.Create(&user)
	fmt.Println(user)
}
